package com.euq.controller;

import com.euq.entity.Dept;
import com.euq.log.BusinessLog;
import com.euq.log.Log;
import com.euq.node.DeptNode;
import com.euq.service.DeptService;
import com.euq.utils.SecurityUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DeptController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private DeptService deptService;
    @GetMapping("/list")
    public List<DeptNode> getDeptTree() {
        return deptService.getDeptTree();
    }
    @PostMapping("insert")
    @BusinessLog(logName = "新增部门",logType = "业务日志")
    public Dept insert(String simpleName,String fullName,Integer num,Long pid) {
        log.info("用户{}新增{}", SecurityUtils.getCurrentUser().getUsername(),fullName);
        return deptService.insert(simpleName,fullName,num,pid);
    }
    @PostMapping("update")
    @BusinessLog(logName = "修改部门",logType = "业务日志")
    public Dept update(@RequestBody Dept dept) {
        log.info("用户{}修改{}信息", SecurityUtils.getCurrentUser().getUsername(),dept.getFullName());
        return deptService.update(dept);
    }
    @PostMapping("delete")
    @BusinessLog(logName = "删除部门",logType = "业务日志")
    public Object deleteById(Long id) {
        log.info("用户{}删除部门", SecurityUtils.getCurrentUser().getUsername());
        return deptService.deleteById(id);
    }
}
